home *** CD-ROM | disk | FTP | other *** search
/ Aminet 23 / Aminet 23 (1998)(GTI - Schatztruhe)[!][Feb 1998].iso / Aminet / biz / demo / WildfirePPC.lha / Wildfire_PPC / Bonus / draggadget_r1.0b2 / dragtest.c < prev    next >
C/C++ Source or Header  |  1997-07-23  |  7KB  |  171 lines

  1. #include "include/gadgets/drag.h"
  2. #include <intuition/gadgetclass.h>
  3. #include <intuition/screens.h>
  4. #include <workbench/workbench.h>
  5.  
  6. #include <clib/alib_stdio_protos.h>
  7. #include <proto/intuition.h>
  8. #include <proto/exec.h>
  9. #include <proto/icon.h>
  10. #include "proto/drag.h"
  11.  
  12. struct IntuitionBase *IntuitionBase;
  13. struct Library *IconBase;
  14. struct ClassLibrary *DragBase;
  15. struct Window *win;
  16.  
  17. main()
  18. {
  19.   struct Gadget *dg[2];
  20.   struct Screen *scr;
  21.   APTR sc,dw,group;
  22.   int i;
  23.   struct MsgPort *dwport;
  24.   struct IntuiMessage *msg;
  25.   struct DropMessage *dmsg;
  26.   struct DiskObject *icon,*icon2,*anim[15];
  27.   struct Image *image1[3],*image2[3],*image3[16];
  28.   char buffer[80];
  29.   BOOL done=FALSE;
  30.  
  31.   if(DragBase=(struct ClassLibrary*)OpenLibrary("gadgets/drag.gadget",40))
  32.   {
  33.     if( (IntuitionBase=(struct IntuitionBase*)OpenLibrary("intuition.library",37)) &&
  34.         (IconBase=OpenLibrary("icon.library",37)) )
  35.     {
  36.       scr=LockPubScreen(NULL);
  37.       sc=CreateDContext(scr);
  38.       group=NewDragGroup();
  39.       if(win=OpenWindowTags(NULL,WA_Left,100,
  40.                                  WA_Top,100,
  41.                                  WA_Width,200,
  42.                                  WA_Height,200,
  43.                                  WA_Title,(ULONG)"drag&drop-test",
  44.                                  WA_IDCMP,IDCMP_CLOSEWINDOW|IDCMP_MOUSEBUTTONS,
  45.                                  WA_CloseGadget,TRUE,
  46.                                  WA_DragBar,TRUE,
  47.                                  WA_DepthGadget,TRUE,
  48.                                  WA_SimpleRefresh,TRUE,
  49.                                  WA_GimmeZeroZero,TRUE,
  50.                                  WA_NoCareRefresh,TRUE,NULL))
  51.       {
  52.         if( (icon=GetDiskObject("sys:prefs/locale")) &&
  53.             (icon2=GetDiskObject("sys:prefs/palette")) )
  54.         {
  55.           for(i=0;i<15;i++)
  56.           {
  57.             sprintf(buffer,"icons/t%d",i+1);
  58.             anim[i]=GetDiskObject(buffer);
  59.             image3[i]=anim[i]->do_Gadget.GadgetRender;
  60.           }
  61.           image3[15]=NULL;
  62.           image1[0]=icon->do_Gadget.GadgetRender;
  63.           image1[1]=icon->do_Gadget.SelectRender;
  64.           image1[2]=NULL;
  65.           image2[0]=icon2->do_Gadget.GadgetRender;
  66.           image2[1]=icon2->do_Gadget.SelectRender;
  67.           image2[2]=NULL;
  68.           if(dg[0]=NewObject(DragBase->cl_Class,NULL,
  69.                                    GA_Left,20,
  70.                                    GA_Top,20,
  71.                                    GA_ID,0,
  72.                                    DGA_Context,sc,
  73.                                    DGA_DragGroup,group,
  74.                                    DGA_ExtSelect,TRUE,
  75.                                    DGA_DragAnim,image3,
  76.                                    GA_Image,image1[0],
  77.                                    GA_SelectRender,image1[1],
  78.                                    GA_RelVerify,TRUE,
  79.                                    GA_Highlight,(icon->do_Gadget.Flags) & GFLG_GADGHIGHBITS,
  80.                                    NULL))
  81.           {
  82.             if(dg[1]=NewObject(DragBase->cl_Class,NULL,
  83.                                      GA_Left,20,
  84.                                      GA_Top,70,
  85.                                      GA_ID,1,
  86.                                      GA_Previous,(ULONG)dg[0],
  87.                                      DGA_Context,sc,
  88.                                      DGA_DragGroup,group,
  89.                                      DGA_ExtSelect,TRUE,
  90.                                      GA_Image,image2[0],
  91.                                      GA_SelectRender,image2[1],
  92.                                      GA_RelVerify,TRUE,
  93.                                      GA_Highlight,(icon2->do_Gadget.Flags) & GFLG_GADGHIGHBITS,
  94.                                      NULL))
  95.             {
  96.               if(dwport=CreateMsgPort())
  97.               {
  98.                 dw=AddDropWindow(sc,1,0,win,dwport);
  99.                 AddGList(win,dg[0],-1,2,NULL);
  100.                 RefreshGList(dg[0],win,NULL,2);
  101.                 while(!done)
  102.                 {
  103.                   Wait((1<<win->UserPort->mp_SigBit)|(1<<dwport->mp_SigBit));
  104.  
  105.                   while(dmsg=(struct DropMessage*)GetMsg(dwport))
  106.                   {
  107.                     struct DragInfo *di=dmsg->dm_DragInfo;
  108.                     WORD woleft=win->LeftEdge + win->BorderLeft;
  109.                     WORD wotop =win->TopEdge + win->BorderTop;
  110.  
  111.                     while(di)
  112.                     {
  113.                       RemoveGadget(win,dg[di->id]);
  114.                       EraseImage(win->RPort,dg[di->id]->GadgetRender,
  115.                                  dg[di->id]->LeftEdge,dg[di->id]->TopEdge);
  116.                       SetGadgetAttrs(dg[di->id],win,NULL,
  117.                                       GA_Left,di->mouse.X - woleft - di->offset.X,
  118.                                       GA_Top,di->mouse.Y - wotop - di->offset.Y,
  119.                                       NULL);
  120.                       AddGadget(win,dg[di->id],0);
  121.                       di=di->next;
  122.                     }
  123.                     RefreshGadgets(win->FirstGadget,win,NULL);
  124.  
  125.                     ReplyMsg((struct Message*)dmsg);
  126.                   }
  127.  
  128.                   while(msg=(struct IntuiMessage*)GetMsg(win->UserPort))
  129.                   {
  130.                     switch (msg->Class)
  131.                     {
  132.                       case IDCMP_CLOSEWINDOW:
  133.                         done=TRUE;
  134.                         break;
  135.                       case IDCMP_MOUSEBUTTONS:
  136.                         if(msg->Code==SELECTDOWN)
  137.                         {
  138.                           SetGadgetAttrs(dg[0],win,NULL,GA_Selected,FALSE,NULL);
  139.                           SetGadgetAttrs(dg[1],win,NULL,GA_Selected,FALSE,NULL);
  140.                         }
  141.                     }
  142.                     ReplyMsg((struct Message*)msg);
  143.                   }
  144.                 }
  145.                 RemoveGadget(win,dg[0]);
  146.                 RemoveGadget(win,dg[1]);
  147.                 RemoveDropWindow(dw);
  148.                 DeleteMsgPort(dwport);
  149.               }
  150.               DisposeObject(dg[1]);
  151.             }
  152.             DisposeObject(dg[0]);
  153.           }
  154.           if(icon) FreeDiskObject(icon);
  155.           if(icon2) FreeDiskObject(icon2);
  156.           for(i=0;i<15;i++)
  157.             FreeDiskObject(anim[i]);
  158.         }
  159.         CloseWindow(win);
  160.       }
  161.       FreeDragGroup(group);
  162.       DeleteDContext(sc);
  163.       UnlockPubScreen(NULL,scr);
  164.  
  165.       if(IntuitionBase) CloseLibrary((struct Library*)IntuitionBase);
  166.       if(IconBase) CloseLibrary(IconBase);
  167.     }
  168.     CloseLibrary((struct Library*)DragBase);
  169.   }
  170. }
  171.